<?php
declare (strict_types=1);

namespace app\index\controller;

use think\facade\View;
use think\exception\ValidateException;

class Security extends Base
{
    public function index()
    {
        return View::fetch();
    }

    public function edit($type)
    {
        $title = $type == 'pay_password' ? '修改支付密码' : '修改登录密码';
        View::assign('title', $title);

        return View::fetch();
    }

    public function save()
    {
        $param = $this->request->post('', '', $this->filter);
        try {
            $this->validate($param, 'Security');
        } catch (ValidateException $e) {
            return json(['code' => -1, 'msg' => $e->getError()]);
        }

        return json(\app\common\model\User::security($param, $this->user));
    }
}